<?php
if(isset($_POST['gpid']))
{	
session_start();
$user = $_SESSION['user'];
require_once("../connection.php");
}
else
require_once("php/connection.php");

//things required $User, $type and $reduced (true or false)
// the first variable is the currenly logged in user
// the second variable is for the group this post box will submit to
// and the third variable for whether u want a reduced functionality postbox
if($user)
{
	if(!isset($reduced_postbox)) 
	$reduced_postbox = "false";
	
	if($reduced_postbox=="true")
	{	?>
		
	<div>
	<form onsubmit="return false;">
	<input type="text" style="padding:5px;width:450px;border:1px solid #555" id="post_box_<?php echo $type; ?>"  autocomplete="off" placeholder="write a message.." onkeyup='type_stat("<?php echo $type; ?>","<?php echo $user; ?>")'/>
 	
 	<input type="submit" onclick='submit_postbox(<?php echo $user; ?>,this,"<?php echo $type; ?>")' value="Post" class="button"/><br> 
 	<span style="font-size:8pt">
 	<!--<span class="formatting_help a" style="color:#555;" onclick='show_fhelp(this,"show")'>Formatting Help</span>-->
 	<span class="formatting_help a" style="color:#555;" onclick='$("#emoticon_fhelp").slideToggle();'>Emoticons</span>
 	 
 	</span>
 	&nbsp;<span id="postbox_err_msg_<?php echo $type; ?>"></span> 
 	<span class="postbox_media_val_<?php echo $type; ?>" style="display:none"></span>
 	
 	<!-- for the formatting help -->
 	<div style="padding:10px;display:none;margin-bottom:5px;margin-top:5px;background:#f1f1f1;border:1px solid #aaa;border-radius:5px" id="emoticon_fhelp">
	<img src="images/chat/Smile.png" style="vertical-align:middle" class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " :)");' />
	<img src="images/chat/Wink.png" style="vertical-align:middle"  class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " ;)");'>
	<img src="images/chat/Tongue.png" style="vertical-align:middle"  class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " :P");'/>
	<img src="images/chat/Ambivalent.png" style="vertical-align:middle"  class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " :|");'/>
	<img src="images/chat/Laugh.png" style="vertical-align:middle"  class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " :D");'/>
	<img src="images/chat/Hot.png" style="vertical-align:middle"  class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " B)");'/>
	<img src="images/chat/Undecided.png" style="vertical-align:middle"  class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " :/");'/>
	<img src="images/chat/Frown.png" style="vertical-align:middle"  class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " :(");'/>
	<img src="images/chat/Kiss.png" style="vertical-align:middle"  class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " :*");'/>
	<img src="images/chat/Crying.png" style="vertical-align:middle"  class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " ;(");'/>
	<img src="images/chat/Angel.png" style="vertical-align:middle"   class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " O:-)");'/>
	<img src="images/chat/Confused.png" style="vertical-align:middle"   class="a" onclick='$("#post_box_<?php echo $type; ?>").val($("#post_box_<?php echo $type; ?>").val() + " o_O");'/>	
	</div>
	<div style="padding:10px;display:none;margin-bottom:10px;margin-top:5px" class="err_box" id="fhelp">
	For linebreak use tag: [br] For bold: [b]bold[/b] will give <b>bold</b>
	</div>
	<?php $res = mysql_query("SELECT * FROM site_user_meta WHERE `fbid`='$user'");
	?>
	<input id="postbox_postas_<?php echo $type; ?>" type="hidden" value="<?php echo mysql_result($res,0,'name'); ?>"/>
	</form>
	</div>
	<?php
	
	}
	else
{
?>

<div> <!-- for assisting in jquery --> 
<div style="border:1px solid #faa;border-radius:2px">
  
<div contenteditable="true" style="width: 96%;border: none;padding:10px;outline:none;font-size:11pt" class="cfont1 pb_postingarea" id="post_box_<?php echo $type; ?>" onkeydown='postbox_changed1(event, "<?php echo $type; ?>")' onkeyup='postbox_changed2(event, "<?php echo $type; ?>")' placeholder="Whats on your mind?"></div>
<!-- the right aligned content for the characters left and help-->
<div style="padding:3px;font-size:80%">
<span id="postbox_err_msg_<?php echo $type; ?>"></span> 
<span id="postbox_media_val_<?php echo $type; ?>" style="display:none"></span>

<span style="position:relative;float:right">  
<span id="postbox_length_<?php echo $type; ?>">400 characters left</span> &nbsp;
<span class="formatting_help a" style="color:#555" onclick='show_fhelp(this,"show")'>help</span>
</span>
<div class="clear"></div>
</div>


<table style="width:100%;background:#f1f1f1;"><tr>
<td valign="top">
<!-- for image/video posting -->
<?php

$temp = mysql_query("SELECT `points` FROM site_user_meta WHERE `fbid`='$user'");
$points = mysql_result($temp,0,'points');

if(1) //($points >= 50)
{

?>
<div style="padding:10px;max-height:250px;overflow:auto" id="postbox_media_<?php echo $type; ?>">
<span class="a" onclick='post_insert_media(this,"img", "<?php echo $type; ?>")'>Attach Image</span> &nbsp;  
<span class="a" onclick='post_insert_media(this,"vid", "<?php echo $type; ?>")'>Attach Video</span>
</div>
<?php
}
?>
</td>
<td valign="top" style="width:35%">
<!-- submit button and post as -->
<div style="padding:2px">
<input type="submit" onclick='submit_postbox(<?php echo $user; ?>,this,"<?php echo $type; ?>")' class="button" value="Post" />
</form>
<!-- select as : three options -->	
	
as 
<?php 
$res1 = mysql_query("SELECT * FROM site_user_meta WHERE `fbid`='$user'");
if($postbox_type=="nonan")
{
	echo mysql_result($res1,0,'name').' <input type="hidden" id="postbox_postas_'.$type.'" value="name_'.mysql_result($res1,0,'name').'"/>';	
}
else
	{
		?>
<select id="postbox_postas_<?php echo $type; ?>" style="width:100px">
<option value="anonymous" selected="selected">Anonymous</option>
<option value="name_<?php echo mysql_result($res1,0,'name'); ?>"><?php echo mysql_result($res1,0,'name'); ?></option>
</select>
<?php
	}
	?>
<img src="images/arrow_up_40.png" style="width:20px;cursor:pointer;vertical-align:middle;opacity:0.3" onclick='pb_alter("<?php echo $type;?>");'>
</div>

</td>

</tr></table>

</div> <!-- text area plus media end -->

<!-- for the formatting help -->
<div style="padding:10px;display:none;margin-bottom:10px;margin-top:5px" class="err_box" id="fhelp">
For bold: [b]bold[/b] will give <b>bold</b>
</div>

		


</div>	
<?php
}

}
else {
	echo '<div class="err_box small-font">You need to be logged in to post here.</div>';
}

?>